import store from '../store/index'
import { initGlobalState } from 'qiankun'

// 定义全局下发的数据
export const initialState = store.state

// 初始化全局下发的数据
export const qiankunActions = initGlobalState(initialState)

// 检测全局下发数据的改变
qiankunActions.onGlobalStateChange((newState, prev) => {
  // state: 变更后的状态; prev 变更前的状态
  console.log('main change', JSON.stringify(newState), JSON.stringify(prev))

  for (const key in newState) {
    initialState[key] = newState[key]
  }
})
